<?php
/**
 * Reads config data of apps and checks the access
 *
 * @author     Mario Schillermann <info@rockit-flash.com>
 * @encoding   UTF-8 äöüßÖÄÜ
 * @copyright  © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license    GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @uses       Zend_Db_Table_Abstract
 * @category   Module
 * @package    Dashboard
 * @subpackage Model
 * @todo
 */

class Dashboard_Model_App
{

    /**
     * Search after all allowed apps
     * 
     * @return array|boolean List of allowed apps
     */
    public function getAllowed()
    {
        try {
            $apps = array();
            $user = array();
            $resources = array();

            $auth = Zend_Auth::getInstance();
            $user = $auth->getStorage()->read();
            $resources = $user["Zend_Acl"]->getResources();
            
            foreach ($resources as $resource) {

                $tmp = explode("_", $resource);
                if ($tmp[1] == "app") {
                    if ($user["Zend_Acl"]->isAllowed(null, $resource, "index")) {
                        
                        $path = APPLICATION_PATH . "/modules/" . $tmp[0] . "/configs/app.ini";
                        $config = new Zend_Config_Ini($path, 'app');
                        $apps[$tmp[0]] = $config->name;
                    }
                }
            }

            return $apps;


        } catch (Zend_Exception $e) {
            error_log(print_r($e, true));
            return false;
        }
    }
}